package com.hntest.service.impl;

import com.hntest.dao.RechargeOfflineDao;
import com.hntest.entity.Pager;
import com.hntest.entity.RechargeOffline;
import com.hntest.service.RechargeOfflineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("rechargeOfflineService")
public class RechargeOfflineServiceImpl implements RechargeOfflineService {

    @Autowired
    private RechargeOfflineDao rechargeOfflineDao;

    public void setRechargeOfflineDao(RechargeOfflineDao rechargeOfflineDao) {
        this.rechargeOfflineDao = rechargeOfflineDao;
    }

    @Override
    public int getCounts(RechargeOffline rechargeOffline) {
        return rechargeOfflineDao.getCounts(rechargeOffline);
    }

    @Override
    public List<RechargeOffline> getListByPage(Pager pager, RechargeOffline rechargeOffline,String time1,String time2) {
        if (time1!=null && time1.equals("")){
            time1=null;
        }
        if (time2!=null && time2.equals("")){
            time2=null;
        }
        //将值存入map中
        Map<String, Object> map = new HashMap<>();
        map.put("pageStart", 1);
        map.put("pageEnd", 10000);
        map.put("time1",time1);
        map.put("time2",time2);
        //查询总数量
        pager.setTotalCounts(rechargeOfflineDao.getListByPage(map).size());

        map.put("rechargeOffline", rechargeOffline);
        map.put("pageStart", (pager.getCurrPage() - 1) * pager.getPageSize() + 1);
        map.put("pageEnd", pager.getCurrPage() * pager.getPageSize());
        map.put("time1",time1);
        map.put("time2",time2);
        //将map中带回的数据保存到list集合中返回
        List<RechargeOffline> list = rechargeOfflineDao.getListByPage(map);
        return list;
    }

    @Override
    public List<RechargeOffline> getAllState() {
        return rechargeOfflineDao.getAllState();
    }

    @Override
    public int insert(RechargeOffline rechargeOffline) {
        return rechargeOfflineDao.insert(rechargeOffline);
    }

    @Override
    public RechargeOffline getRechargeOfflineById(int cbiid) {
        return rechargeOfflineDao.getRechargeOfflineById(cbiid);
    }

    @Override
    public int update(RechargeOffline rechargeOffline) {
        return rechargeOfflineDao.update(rechargeOffline);
    }
}
